package com.wx.mall.user.service.impl;

import com.wx.mall.common.exception.BusinessException;
import com.wx.mall.common.exception.code.TaskRewardResponseCode;
import com.wx.mall.user.entity.TaskReward;
import com.wx.mall.user.mapper.TaskRewardMapper;
import com.wx.mall.user.service.ITaskRewardService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wx.mall.user.service.ITaskRewardService;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  任务奖励服务实现类
 * </p>
 *
 * @author ljl
 * @since 2020-03-18
 */
@Service
public class TaskRewardServiceImpl extends ServiceImpl<TaskRewardMapper, TaskReward> implements ITaskRewardService {

    @Override
    public TaskReward getTaskReward() {
        TaskReward taskReward = baseMapper.selectById(1);
        if (taskReward == null){
            throw new BusinessException(TaskRewardResponseCode.QUERY_ERROR);
        }
        return taskReward;
    }

    @Override
    public void setTaskReward(TaskReward taskReward) {
        taskReward.setId(1);
        int update = baseMapper.updateById(taskReward);
        if (update == 0){
            throw new BusinessException(TaskRewardResponseCode.UPDATE_ERROR);
        }
    }
}
